package com.acme.logginglab;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.acme.logginglab.mylogger.LogLevel;

public class LoggingTest {
	private static Logger log = LoggerFactory.getLogger(LoggingTest.class.getName());
	
	private final static int NUM_CYCLES = 10000;
	
	public static void main(String[] args) throws InterruptedException {
		ExecutorService executor = Executors.newFixedThreadPool(10);
		for (int i=0; i<NUM_CYCLES; i++) {
			LogLevel l = ((i%3) ==0) ? LogLevel.INFO : ((i%3)==1 ? LogLevel.DEBUG : LogLevel.ERROR);
			executor.submit(new LogWriter(Integer.toString(i),l, log));
		}
		executor.shutdown();
		boolean terminated = executor.awaitTermination(5, TimeUnit.SECONDS);
	}
}
class LogWriter implements Runnable {
	private String name;
	private LogLevel l;
	private Logger log;
	public LogWriter(String name, LogLevel l, Logger log) {
		this.name = name;
		this.l = l;
		this.log = log;
	}
	public void run() {
		switch (l) {
		case INFO:
			log.info ("Hello! My name is {}", name);
			break;
		case DEBUG:
			log.debug ("Hello! My name is {}", name);
			break;
		case ERROR:
			log.error ("Hello! My name is {}", name);
			break;
		}
	}
};